package com.mall.shopping.services;

import com.mall.shopping.IContentService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.converter.ContentConverter;
import com.mall.shopping.dal.entitys.PanelContent;
import com.mall.shopping.dal.persistence.PanelContentMapper;
import com.mall.shopping.dto.NavListResponse;
import com.mall.shopping.dto.PanelContentDto;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @program: mall-parent
 * @description:
 * @author: zhijie
 * @create: 2021-12-13 21:04
 **/
@Service
public class ContentServiceImpl implements IContentService {
    @Autowired
    PanelContentMapper panelContentMapper;
    @Autowired
    ContentConverter contentConverter;

    @Override
    public NavListResponse queryNavList() {
        NavListResponse navListResponse = new NavListResponse();
        Example example = new Example(PanelContent.class);
        example.createCriteria().andEqualTo("panelId", 0);
        List<PanelContentDto> panelContentDtos = null;
        try {
            List<PanelContent> panelContents = panelContentMapper.selectByExample(example);
            panelContentDtos = contentConverter.panelContents2Dto(panelContents);
        } catch (Exception e) {
            navListResponse.setCode(ShoppingRetCode.SYSTEM_TIMEOUT.getCode());
            navListResponse.setMsg(ShoppingRetCode.SYSTEM_TIMEOUT.getMessage());
            return navListResponse;
        }
        navListResponse.setPannelContentDtos(panelContentDtos);
        navListResponse.setCode(ShoppingRetCode.SUCCESS.getCode());
        navListResponse.setMsg(ShoppingRetCode.SUCCESS.getMessage());
        return navListResponse;
    }
}
